/** 打开后台页 */
document.getElementById("openback").addEventListener("click", () => {
  console.log("点击事件");
  window.open(chrome.extension.getURL("back.html"));
});

/**获取标题页标题 */
document.getElementById("getbacktitle").addEventListener("click", () => {
  console.log("点击事件");
  const bg = chrome.extension.getBackgroundPage();
  alert(bg.document.title);
});

/**设置后台页标题 */
document.getElementById("setbacktitle").addEventListener("click", () => {
  var title = prompt("请输入后台页新标题", "新标题");
  var bg = chrome.extension.getBackgroundPage();
  bg.document.title = title;
  alert(bg.document.title);
});

/**调取后台js */
document.getElementById("callbackjs").addEventListener("click", () => {
  console.log("点击调用后台页js");
  var bg = chrome.extension.getBackgroundPage();
  bg.backjs();
});

document.getElementById("submit").addEventListener("click", () => {
  chrome.storage.sync.get("total", (budget) => {
    var totalAmount = 0;
    if (budget.total) {
      totalAmount = parseFloat(budget.total);
    }
    var amount = document.getElementById("amount").val();
    if (amount) {
      totalAmount += parseFloat(amount);
      chrome.storage.set({ total: totalAmount });
    }
    document.getElementById("total").text(totalAmount);
    document.getElementById().val("");
  });
});
